package com.mwy.springsessiondemo1.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class Controller1 {

    @ResponseBody
    @RequestMapping("/show1")
    public String show1(){
        System.out.println("进入show1方法");
        return "你好，世界";
    }

    @RequestMapping("/set")
    @ResponseBody
    public String set(HttpSession session){
        System.out.println("进入set方法");
        session.setAttribute("data","我的session数据");
        return "session设置成功";
    }

    @ResponseBody
    @RequestMapping("/get")
    public String get(HttpSession session){
        System.out.println("进入get方法");
        String data = (String) session.getAttribute("data");
        return data;
    }
}
